package com.zerdoor.controller;

import com.zerdoor.pagehelper.PageHelper;
import com.zerdoor.pagehelper.PageInfo;
import com.zerdoor.service.PrincipalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Project: acg
 * Module ID: 006
 * Comments: 委托方显示
 * JDK version used: JDK1.7
 * Namespace: controller
 * Author：xiaoji
 * Create Date：2014-11-14
 * Modified By：   <修改人中文名或拼音缩写>
 * Modified Date:  <修改日期，格式:YYYY-MM-DD>
 * Why & What is modified  <修改原因描述>
 * Version:                  <版本号>
 */
@Controller
@RequestMapping("/principal")
public class PrincipalController {

    @Autowired
    private PrincipalService principalService;

    /**
     * FunName:           principalView
     * Description :      委托方个人主页
     * @return String：返回首页页面
     * @Author:       xiaoji
     * @Create Date: 2014-10-27
     */
    @RequestMapping(value="/principalView", method = RequestMethod.GET)
    public String principalView(Integer principalId,Model model){
        //个人资料
        model.addAttribute("priinfos",principalService.getPriInfos(principalId));
        model.addAttribute("principalId",principalId);
        return "/principalView/index";
    }

    /**
     * 委托方个人主页发布任务
     * @param principalId 委托方ID
     * @param page 第几页
     * @param rows 每页显示条数
     * @return
     */
    @RequestMapping(value = "getPrincipTask",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getPrincipTask(Integer principalId,int page,int rows){
        Map<String, Object> map = new HashMap<String,Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = principalService.getPrincipTask(principalId);
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return  map;
    }

    /**
     * 委托方个人主页发布竞赛活动
     * @param principalId 委托方ID
     * @param page 第几页
     * @param rows 每页显示条数
     * @return
     */
    @RequestMapping(value = "getPrincipRace",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getPrincipRace(Integer principalId,int page,int rows){
        Map<String, Object> map = new HashMap<String,Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = principalService.getPrincipRace(principalId);
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return  map;
    }

    /**
     * 评价
     * @param principalId 委托方ID
     * @param page 第几页
     * @param rows 每页显示条数
     * @return
     */
    @RequestMapping(value = "getPrincipAppraise",method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getPrincipAppraise(Integer principalId,int page,int rows){
        Map<String, Object> map = new HashMap<String,Object>();
        PageHelper.startPage(page, rows);
        List<Map<String, Object>> list = principalService.getPrincipAppraise(principalId);
        PageInfo pageInfo = new PageInfo(list);
        map.put("pageInfo",pageInfo);
        return  map;
    }

}
